/*!
  @file network_io.cpp
  @brief 
  @author Kyohei Otsu <kyon@ac.jaxa.jp>
  @date April, 2013
*/

#include "png/libpng_helper.h"
#include "core/core.h"

using namespace std;

namespace png
{

bool PNG::recv(FILE *fp)
{

  //-- receive from file pointer
  bool success = decode(fp, data_);
  if (success) {
    if (png_sig_cmp(data_[0], 0, 8)) {
      ERROR("Invalid PNG file received");
      releaseMemory();
      return false;
    }
  }

  return success;
}

bool PNG::send(FILE *fp)
{
  if (!memory_alloced_) {
    INFO("image not loaded");
    return false;
  }

  bool success = encode(data_, fp);

  return success;
}

} // end of namespace
